package zut.cs.liziflower.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import zut.cs.liziflower.entity.Consumer;
import zut.cs.liziflower.mapper.ConsumerMapper;
import zut.cs.liziflower.service.IConsumerService;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xuwenke
 * @since 2022-05-17
 */
@Service
public class ConsumerServiceImpl extends ServiceImpl<ConsumerMapper, Consumer> implements IConsumerService {
    @Resource
    private ConsumerMapper consumerMapper;

    @Override
    public Consumer getByNameAndPassword(String username, String password) {

        return consumerMapper.getByNameAndPassword(username, password);
    }

    @Override
    public Consumer login(String username, String password) {
        QueryWrapper<Consumer> wrapper = new QueryWrapper<>();//条件构造器
        wrapper.eq("username", username)
                .and(q -> q.eq("password", password));
        return consumerMapper.selectOne(wrapper);
    }

    @Override
    public boolean updateInfo(Integer userid, Integer age, String sex, String phone, String password) {
        int flag = consumerMapper.updateInfo(userid, age, sex, phone, password);
        if (flag == 1) {
            return true;
        }
        return false;
    }

    @Override
    public int updateMoneyAndScore(Integer userid, BigDecimal money, Integer score) {

        return consumerMapper.updateMoneyAndScore(userid,money,score);
    }

    @Override
    public int updateAvator(Integer userid, String url) {
        return consumerMapper.updateAvator(userid,url);
    }

}
